#include "gtest/gtest.h"


#include "Cast.h"
#include "CastComparator.h"

using namespace  helper;
using namespace  demo;


TEST(CastTest, test){

  Cast<uint32_t> cast("test");
  uint32_t src = 100;

  auto slice = cast.toSlice(src);
  ASSERT_EQ((void*)&src, (void*)slice.data());
  ASSERT_EQ(sizeof(src), slice.size());

  {
    auto && p = cast.fromSlice(slice);
    ASSERT_TRUE(p.first);
    ASSERT_EQ(&src, &p.second);
  }
  {
    auto && [ok, type] = cast.fromSlice(slice);
    ASSERT_TRUE(ok);
    ASSERT_EQ(&src, &type);
  }


  {
    uint32_t l = 1;
    uint32_t r = 2;
    ASSERT_TRUE(cast.compare(cast.toSlice(l), cast.toSlice(r)) < 0);
  }
  {
    uint32_t l = 1;
    uint32_t r = 1;
    ASSERT_TRUE(cast.compare(cast.toSlice(l), cast.toSlice(r)) == 0);
  }
  {
    uint32_t l = 2;
    uint32_t r = 1;
    ASSERT_TRUE(cast.compare(cast.toSlice(l), cast.toSlice(r)) > 0);
  }
}



TEST(CastComparatorTest, test){
  Cast<uint32_t> cast("uint32_t");
  CastComparator<uint32_t> cmp(cast);
  uint32_t l = 1;
  uint32_t r = 2;
  ASSERT_TRUE(cmp.Compare(cast.toSlice(l), cast.toSlice(r)) < 0);
}


TEST(newCastComparatorTest, test){
  Cast<uint32_t> cast("uint32_t");
  auto * cmp = newCastComparator<uint32_t>(cast);

  uint32_t l = 1;
  uint32_t r = 2;
  ASSERT_TRUE(cmp->Compare(cast.toSlice(l), cast.toSlice(r)) < 0);
}
